package com.freak.freakmusic.net.request

import okhttp3.MediaType
import okhttp3.RequestBody
import java.util.*

/**
 * form_data 方式请求数据转换
 * aip接口需要使用 @Multipart注解 参数使用@PartMap或者@Part注解  使用@Part注解需要使用RequestBody格式的参数
 *
 * @author freak
 * @date 2019/9/11.
 */
object FormDataRequestBody {
    fun generateRequestBody(requestDataMap: Map<String, String>): Map<String, RequestBody> {
        val requestBodyMap = HashMap<String, RequestBody>()
        for (key in requestDataMap.keys) {
            val requestBody = RequestBody.create(
                MediaType.parse("multipart/form-data"),
                if (requestDataMap[key] == null) "" else requestDataMap[key]
            )
            requestBodyMap[key] = requestBody
        }
        return requestBodyMap
    }

}
